package cn.supermaster.management.web.controller.common;

import cn.supermaster.management.common.response.WebResponse;
import cn.supermaster.management.web.service.common.ICommonService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * All rights Reserved, Designed By www.super-bytecode.com
 *
 * @ProjectName: supermaster-management
 * @Package: cn.supermaster.management
 * @ClassName: SwaggerConfiguration
 * @Description: [通用请求处理]
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2021/1/9 13:36
 * @Version: V1.0
 * @Copyright: 2021 www.super-bytecode.com Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@Controller
public class CommonController {
    private static final Logger logger = LoggerFactory.getLogger(CommonController.class);

    @Autowired
    private ICommonService commonService;

    /**
     * @Description: [通用下载请求]
     */
    @GetMapping("common/download")
    public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {
        commonService.doFileDownload(request, response, fileName, delete);
    }

    /**
     * @Description:通用上传请求
     */
    @PostMapping("/common/upload")
    @ResponseBody
    public WebResponse uploadFile(MultipartFile file) throws Exception {
        return commonService.doUploadFile(file);
    }

    /**
     * @Description:本地资源通用下载
     */
    @GetMapping("/common/download/resource")
    public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response) {
        commonService.doResourceDownload(request, response, resource);
    }
}
